import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
import { DevelopState, Soldier } from '../entity/Soldier';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';
import { ProPanel } from './ProPanel';
import { EventManager } from '../event/EventManager';
import { TrainNumber } from './TrainNumber';
const { ccclass, property } = _decorator;

@ccclass('SoldierCover')
export class SoldierCover extends Component {
    @property(Sprite)
    border:Sprite;
    @property(Sprite)
    cover:Sprite;
  
    @property(Label)
    soldierName:Label

   
   
    @property(SpriteFrame)
    border1:SpriteFrame
    @property(SpriteFrame)
    border2:SpriteFrame
    @property(SpriteFrame)
    border3:SpriteFrame

    soldierData:Soldier

    start() {
        
        this.cover.node.on(Node.EventType.TOUCH_END, this.onTrain, this)
    }

    async setData(soldier:Soldier){
        this.soldierData = soldier

        this.soldierName.string = soldier.name
        if(soldier.developed == DevelopState.Developed){
          this.border.spriteFrame = this.border1
         
        } else{
            this.border.spriteFrame = this.border3
           
        }

        this.cover.spriteFrame = await soldier.getHeadImg()
    }

    async onTrain(){
        
        // if(this.soldierData.developed != DevelopState.Developed){
        //     UIManager.instance.closeUI(PrefabEnum.TrainNumber)
        //     return
        // }
        
        UIManager.instance.closeUI(PrefabEnum.TrainNumber)
        let ui = await UIManager.instance.openUI(PrefabEnum.TrainNumber)
        ui.getComponent(TrainNumber).setData(this.soldierData)

        
    }

    onCover(){
       
    }
}


